﻿package graph 
{
	/**
	 * ...
	 * @author s
	 */
	public class Graph
	{
		protected var _edges:Vector.<Edge>;
		protected var _nodes:Vector.<Node>;

		public function Graph() 
		{
			_nodes = new Vector.<Node>;
			_edges = new Vector.<Edge>;
		}
		
		public function addNode(node:Node):void 
		{
			_nodes.push(node);
		}
		
		public function removeNode(node:Node):void
		{
			//
		}
		
		public function removeEdge(edge:Edge):void 
		{
			//
		}
		
		public function defineNewEdge(srcNode:Node, dstNode:Node, weight:Number):void 
		{
			if(srcNode.edgeTo(dstNode) == null){
				var edge:Edge = new Edge(srcNode, dstNode, weight);
				srcNode.addAdjacent(edge);
				dstNode.addAdjacent(edge);
				_edges.push(edge);
			}
			else {
				srcNode.edgeTo(dstNode).weight += weight;
			}
		}
		
		/*
		 * getter, setter
		 */
		public function node(i:int):Node
		{
			if(i >= 0 && i < _nodes.length){
				return _nodes[i];
			}
			else {
				return null;
			}
		}
		
		public function edge(i:int):Edge
		{
			if(i >= 0 && i < _edges.length){
				return _edges[i];
			}
			else {
				return null;
			}
		}
	}

}